
package unit8;

import java.util.ArrayList;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

	
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        TreeMap<String,TreeSet<Integer>>map=new TreeMap<String,TreeSet<Integer>>();
        ArrayList<String>strList=new ArrayList<String>();
        strList.add("Begin");
        int numOfline=1;   
        while(in.hasNext())
        {
        	String line=in.nextLine();
        	if(line.equals("!!!!!"))
        	{
        		break;
        	}
        	Scanner strIn=new Scanner(line);
        	while(strIn.hasNext())
        	{
        		String str=strIn.next();
        		if(map.containsKey(str))
        		{
        			map.get(str).add(numOfline);
        		}
        		else
        		{
        			TreeSet<Integer>newSet=new TreeSet<Integer>();
        			newSet.add(numOfline);
        			map.put(str, newSet);
        		}
        	}
        	strIn.close();
        	strList.add(line);
        	numOfline++;
        }
        for (Entry<String, TreeSet<Integer>> entry: map.entrySet()) {
        	System.out.println( entry.getKey()+"="+entry.getValue());
        }
        
        while(in.hasNext())
        {
        	String line=in.nextLine();
        	Scanner strIn=new Scanner(line);
        	ArrayList<Integer>list=new ArrayList<Integer>();
        	boolean first=true;
        	while(strIn.hasNext())
        	{
        		String str=strIn.next();
        		TreeSet<Integer>set=map.get(str);
        		if(first)
        		{
        			if(set!=null)
        				list.addAll(set);
        			first=false;
        		}
        		else
        			list.retainAll(set);
        	}
        	if(list.isEmpty())
        	{
        		System.out.println("found 0 results");
        	}
        	else
        	{
        		System.out.println(list);
        		for(int i=0;i<list.size();i++)
        		{
        			System.out.print("line "+list.get(i)+":");
        			System.out.println(strList.get(list.get(i)));
        		}
        	}
        	strIn.close();
        }
        
        
        
        in.close();
    }
	

}
